package com.hjm.common.utils.yh;

import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;


@SuppressWarnings("unchecked")
public class PMap<Key, Type> {

	private Map<Key, Type> packMap = new LinkedHashMap<Key, Type>();

	public void put(Key key, Type value) {
		packMap.put(key, value);
	}

	public Type get(Key key) {
		return packMap.get(key);
	}

	public void remove(Key key) {
		packMap.remove(key);
	}

	public Set<Key> keySet() {
		return packMap.keySet();
	}

	public Type getNoNull(Key key) throws Exception {
		Type newType = packMap.get(key);
		return newType != null ? newType : (Type) "";
	}

	public String getNoNullFormatDate1(String dealDate) throws Exception {
		try {
			dealDate = DateUtil.appendField(dealDate.substring(0, 4), "-",
					dealDate.substring(4, 6), "-", dealDate.substring(6));
			return dealDate != null ? (dealDate) : ("");
		} catch (Exception e) {
			return "";
		}
	}


	public String getNoNullFormatDate2(String dealDate) throws Exception {
		try {
			dealDate = DateUtil.appendField(dealDate.substring(0, 4), "年",
					dealDate.substring(4, 6), "月", dealDate.substring(6), "日");
			return dealDate != null ? (dealDate) : ("");
		} catch (Exception e) {
			return "";
		}
	}

	public String getNoNullAndHasCharacterD(Key key) throws Exception {
		try {
			String date = packMap.get(key).toString();
			String newDate = DateUtil.appendField(
					DateUtil.getCurrentDateTime("yyyy"), "-",
					date.substring(0, 2), "-", date.substring(2));
			return newDate != null ? newDate : "";
		} catch (Exception e) {
			return DateUtil.getCurrentDateTime("yyyy-MM-dd");
		}
	}

	public String getNoNullAndHasCharacterT(Key key) throws Exception {
		try {
			String date = packMap.get(key).toString();
			String newDate = DateUtil.appendField(date.substring(0, 2), ":",
					date.substring(2, 4), ":", date.substring(4));
			return newDate != null ? newDate : "";
		} catch (Exception e) {
			return DateUtil.getCurrentDateTime("HH:mm:ss");
		}
	}
}
